package com.app.micaihu.view.army.header

import android.content.Context
import android.content.Intent
import android.os.Bundle
import com.app.base.BaseMvpHeaderView
import com.app.micaihu.R
import com.app.micaihu.configure.Config
import com.app.micaihu.view.army.activity.ArmyOfficialPositionSetListActivity
import com.app.micaihu.view.army.contract.ArmyMemberContract
import com.app.micaihu.view.army.presenter.ArmyMemberPresenter
import com.app.micaihu.view.bean.ArmyCurrentMember
import com.blankj.utilcode.util.ActivityUtils
import kotlinx.android.synthetic.main.army_set_official_position_header.view.*
import java.io.Serializable

/**
 * 任命 列表头部
 */
class ArmySetOfficialPositionHeader(context: Context, gid: String) : BaseMvpHeaderView<ArmyMemberContract.View, ArmyMemberPresenter>(context = context), ArmyMemberContract.View {

    override fun getLayoutId() = R.layout.army_set_official_position_header
    override fun getPresenter() = ArmyMemberPresenter(gid)
    private var gid = ""
    private var level = ""

    init {
        this.gid = gid
    }

    private var armyCurrentMember: ArmyCurrentMember? = null

    override fun setData() {

    }

    override fun addListeners() {
        llAddMember.setOnClickListener {
            armyCurrentMember?.let {
                val intent = Intent(context, ArmyOfficialPositionSetListActivity::class.java)
                val bundle = Bundle()
                bundle.putString(Config.Extra.id, gid)
                bundle.putInt(Config.Extra.max, it.totleNum)
                bundle.putString(Config.Extra.level, level)
                bundle.putSerializable(Config.Extra.list, it.memberList as Serializable)
                intent.putExtras(bundle)
                ActivityUtils.startActivity(intent)
            }

        }
    }

    fun setHeaderData(armyCurrentMember: ArmyCurrentMember?) {
        this.armyCurrentMember = armyCurrentMember
        armyCurrentMember?.let {
            tvMemberLevel.text = it.currentLevel
            tvMemberTitle.text = "拥有此头衔的军团成员(${it.currentNum})人"
            tvArmyDec.text = "当前军团级别最高可以任命${it.totleNum}人"
            tvArmyPositionMax.text = "${it.currentNum}/${it.totleNum}"
        }
    }

    fun setLevel(level: String?) {
        level?.let {
            this.level = it
        }

    }
}